package org.andao.commons.taglib;

import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.tagext.TagSupport;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import freemarker.ext.beans.BeansWrapper;
import freemarker.ext.beans.ResourceBundleModel;

/**
 *  基本的标签支持类. <p>
 * 
 * @author Marco.hu(hzg139@163.com)
 */
public class BaseTagSupport  extends TagSupport{

	private static final long serialVersionUID = 5604202780544434071L;
	
	protected  Logger logger = LoggerFactory.getLogger(getClass());
		
	/**
	 * 定义模板的model map.
	 * @return
	 */
	protected Map<String,Object> getTemplateModelMap(){
		Map<String,Object> map = new HashMap<String,Object>(0);
		try{
			if(null != ResourceBundle.getBundle("seewoClass")){//若有语言定义，则处理语言
				ResourceBundleModel rsbm = new ResourceBundleModel(ResourceBundle.getBundle("seewoClass"), new BeansWrapper());//加载国际化语言
				map.put("bundle", rsbm);
			}
		}catch(Exception e){
			//nothting
		}
		
		return map;
	}
	
	public HttpServletRequest getrequest(){			
		return  (HttpServletRequest)pageContext.getRequest();
	}
	
	public HttpServletResponse getResponse(){
		return (HttpServletResponse)pageContext.getResponse();
	}	
	
	public String getRootUrl(){
		return getrequest().getScheme()+"://"+getrequest().getServerName()+":"+getrequest().getServerPort();
	}
	
	public String getBaseUrl(){
		return getrequest().getScheme()+"://"+getrequest().getServerName()+":"+getrequest().getServerPort()+getrequest().getContextPath();
	}

}
